package voice.main;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import util.TaskHelper;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ContactsActivity  extends ListActivity  {
	public static final int PICK_CONTACT = 1001;
	public static final int CALL_MODE = 1;
	public static final int SMS_MODE = 2;
	private ArrayAdapter<String> adapter;
	private HashMap<String,String> contactList;
	private int mode;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ArrayList<String> values = new ArrayList<String>();
        
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, 
        									android.R.id.text1, values);
        setListAdapter(adapter);
        
        contactList = (HashMap<String,String>) getIntent().getSerializableExtra("CONTACTS_LIST");
        mode = getIntent().getExtras().getInt("MODE");
        
        for (Map.Entry<String, String> entry : contactList.entrySet()) {
            String key = entry.getKey();
    		adapter.add(key);
        }
    }
	
	@Override
	  protected void onListItemClick(ListView l, View v, int position, long id) {
	    if (mode == CALL_MODE) TaskHelper.startCallByNumber(getApplicationContext(), contactList.get(adapter.getItem(position)));
	    if (mode == SMS_MODE) TaskHelper.sendSMSByNumber(getApplicationContext(), contactList.get(adapter.getItem(position))); 
	}
}
